package com.itheima.spring.processor;

import com.itheima.spring.aop.ServiceDynamicProxy;
import com.itheima.spring.service.UserService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @author ：sean
 * @date ：Created in 2020/7/4
 * @description ：
 * @version: 1.0
 */
@Component
public class HmBeanPostProcessor implements BeanPostProcessor {
	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		//System.out.println("Bean 实例化之前:"+beanName);
		return null;
	}

	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		// 所有自定义Bean实例后都被调用此方法
		//System.out.println("Bean 实例化之后"+beanName+" bean:"+bean);
		//System.out.println("bean.getClass().getInterfaces():"+bean.getClass().getInterfaces());
		//System.out.println("bean.getClass().getClass().getName():"+bean.getClass().getName());
		//if(bean.getClass().getInterfaces() != null
		//	&& bean.getClass().getName().contains("service.impl")) {
		//	// JDK代理必须是基于接口，替换为代理对象
		//	bean = new ServiceDynamicProxy(bean).getProxy();
		//}
		return bean;
	}
}
